import random

import requests
import logging
import config


class MenuApi:

    # 获取菜单列表
    @classmethod
    def get_menu_list(cls, token, menuName='', isFrame='', isCache='', visible=''):
        url = config.monitor_domain + f"/system/menu/list?menuName={menuName}&isFrame={isFrame}&isCache={isCache}&visible={visible}"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"get_menu_list url:{url}")
        logging.info(f"get_menu_list resp: {resp.text}")
        return resp

    # 根据菜单编号获取详细信息
    @classmethod
    def get_menu_detail(cls, token, menuId):
        url = config.monitor_domain + f"/system/menu/{menuId}"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"get_menu_detail url:{url}")
        logging.info(f"get_menu_detail resp: {resp.text}")
        return resp

    # 获取菜单下拉树列表
    @classmethod
    def get_treeselect(cls, token, menuName='', isFrame='', isCache='', visible=''):
        url = config.monitor_domain + f"/system/menu/treeselect?menuName={menuName}&isFrame={isFrame}&isCache={isCache}&visible={visible}"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"get_treeselect url:{url}")
        logging.info(f"get_treeselect resp: {resp.text}")
        return resp

